//
// Created by win10 on 2024/12/18.
//
#include <stdio.h>
#include <stdlib.h>

typedef struct Node {
    int data;
    struct BitNode* lchild;
    struct BitNode* rchild;
} BitNode;

BitNode* createNode(int data) {
    BitNode* newNode = (BitNode*)malloc(sizeof(BitNode));
    if(!newNode) {
        printf("内存分配失败\n");
        return NULL;
    }
    newNode->data = data;
    newNode->lchild = NULL;
    newNode->rchild = NULL;
    return newNode;
}

//查找某个值
BitNode * search(BitNode* root, int key) {
    if(!root) {
        return NULL;
    }
    if(root->data == key) {
        return root;
    }
    if(key < root->data) {
        return search(root->lchild, key);
    }
    if(key > root->data) {
        return search(root->rchild, key);
    }

}

//插入某个值
BitNode* insert(BitNode* root, int key) {
    if(!root) {
        root = createNode(key);
    }else if (key < root->data) {
        root->lchild = insert(root->lchild, key);
    }else if (key > root->data) {
        root->rchild = insert(root->rchild, key);
    }else {
        printf("node has been existed");
        return root;
    }
    return root;
}